package com.tyc.expand;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class MyBeanDefinationRegisteryPostPoccessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        System.out.println("当前bean数量为："+beanDefinitionRegistry.getBeanDefinitionCount());
        System.out.println("postProcessBeanDefinitionRegistry==>"+"手动注入bean");
        BeanDefinitionBuilder builder  = BeanDefinitionBuilder.genericBeanDefinition(Red.class);
        beanDefinitionRegistry.registerBeanDefinition("red",builder.getBeanDefinition());

    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        System.out.println("postProcessBeanFactory");
    }
}
